package itsm.isperp.module.service.task;

import itsm.isperp.framework.data.dialect.DialectFactory;
import itsm.isperp.framework.data.domain.DataRequest;
import itsm.isperp.framework.data.domain.DataResponse;
import itsm.isperp.framework.data.domain.PageResponse;
import itsm.isperp.framework.service.BaseService;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.dto.project.ProjectDomain;
import itsm.isperp.module.dto.project.ProjectDomain.ProjectDomainType;
import itsm.isperp.module.entity.task.TskTask;
import itsm.isperp.module.repository.task.TskTaskMapper;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jdbc.support.DatabaseType;
import org.springframework.stereotype.Service;

@Service
public class TskTaskService extends BaseService<TskTask> {

	@Autowired
	protected TskTaskMapper tskTaskMapper;

	@Override
	public TskTaskMapper getRepository() {
		return this.tskTaskMapper;
	}

	@Override
	public DataResponse<Map<String, Object>> findAllDetailByRequest(
			DataRequest request) {
		if (DialectFactory.getDatabaseType() == DatabaseType.MYSQL) {
			return super.findAllDetailByRequest(request);
		} else {
			return this.tskTaskMapper.findAllDetailByRequestInOracle(request);
		}
	}

	public PageResponse<Map<String, Object>> searchAllByFilter(
			JqGridRequest request) {
		request.setProjectDomain(ProjectDomain.newInstance("project_id",
				ProjectDomainType.Technology));
		return tskTaskMapper.searchAllByFilter(request).toPage();
	}

}
